package com.yyge.common.resp;
import com.yyge.common.enums.AckCode;
import lombok.Data;

/**
 * 统一响应模型
 */
@Data
public class R<T> {
    private Integer code;
    private String msg;
    private T data;


    public synchronized static <T> R<T> build(AckCode statusEnum) {
        return build(statusEnum, null);
    }

    public synchronized static <T> R<T> build(AckCode ackCode, T data) {
        R<T> res = new R<>();
        res.setCode(ackCode.code);
        res.setMsg(ackCode.msg);
        res.setData(data);
        return res;
    }



    public synchronized static <T> R<T> build(AckCode ackCode, T data, String msg) {
        R<T> res = new R<>();
        res.setCode(ackCode.code);
        res.setMsg(msg);
        res.setData(data);
        return res;
    }

    public synchronized static <T> R<T> build(Integer status, String msg,T data) {
        R<T> res = new R<>();
        res.setCode(status);
        res.setMsg(msg);
        res.setData(data);
        return res;
    }

    public synchronized static <T> R<T> ok() {
        return build(AckCode.SUCCESS, null);
    }
    public synchronized static <T> R<T> ok(String msg,T data) {
        return build(AckCode.SUCCESS,data, msg);
    }

    public synchronized static <T> R<T> fail(String msg){
         return build(AckCode.FAIL, null,msg);
    }

    public synchronized static <T> R<T> fail(AckCode ackCode,String msg){
         return build(ackCode, null,msg);
    }

    public synchronized static <T> R<T> okHasData(T data) {
        return build(AckCode.SUCCESS, data);
    }

    /***
     * 过期
     *
     * @param message:
     * @return: ApiResult
     */
    public synchronized static <T> R<T> expired(String message) {
        return build(AckCode.TOKEN_FAIL.getCode(), message, null);
    }
}
